/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.teama;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author xiopus
 */
public class Issue {
         private int    issueId;
         private int    appId;
         private String issueSummary;
         private String issueDesc;
         private int    priorityId;
         private int    submitById;
         private int    assignToId;
         private int    statusId;
         private final String createdDate;
    
    /* init to invalid values - for checking */
    public Issue(){
         issueId=-1;
         appId=-1;
         issueSummary=null;
         issueDesc=null;
         priorityId=-1;
         submitById=-1;
         assignToId=-1;
         statusId=-1;
         /* As this is a new Issue, we can set the date to the current date/time */
         DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
         Date date = new Date();       
         createdDate=dateFormat.format(date);
    }     
    
    /* partial constructor to match database values - others are derived */
    public Issue(int issueId, int  appId, String issueSummary, String issueDesc, int priorityId,
                 int submitbyId, String created, int assigntoId, int status_id){
         this.issueId=issueId;
         this.appId=appId;
         this.issueSummary=issueSummary;
         this.issueDesc=issueDesc;
         this.priorityId=priorityId;
         this.submitById=submitbyId;
         this.assignToId=assigntoId;
         this.statusId=status_id;
         this.createdDate = created;
    }
         
    public int getIssueId() {
        return issueId;
    }

    /**
     * @param issueId the IssueId to set
     */
    public void setIssueId(int issueId) {
        this.issueId = issueId;
    }

    /**
     * @return the AppId
     */
    public int getAppId() {
        return appId;
    }

    /**
     * @param appId the AppId to set
     */
    public void setAppId(int appId) {
        this.appId = appId;
    }

    /**
     * @return the AppName
     */
    public String getAppName() {
        return AppListDA.getApp(getAppId()).getName();
    }

    /**
     * @return the AppVersion
     */
    public String getAppVersion() {
        return AppListDA.getApp(getAppId()).getVersion();
    }

    /**
     * @return the IssueSummary
     */
    public String getIssueSummary() {
        return issueSummary;
    }

    /**
     * @param issueSummary the IssueSummary to set
     */
    public void setIssueSummary(String issueSummary) {
        this.issueSummary = issueSummary;
    }

    /**
     * @return the IssueDesc
     */
    public String getIssueDesc() {
        return issueDesc;
    }

    /**
     * @param issueDesc the IssueDesc to set
     */
    public void setIssueDesc(String issueDesc) {
        this.issueDesc = issueDesc;
    }

    /**
     * @return the priorityId
     */
    public int getPriorityId() {
        return priorityId;
    }

    /**
     * @param priorityId the priorityId to set
     */
    public void setPriorityId(int priorityId) {
        this.priorityId = priorityId;
    }

    /**
     * @return the priorityLabel
     */
    public String getPriorityLabel() {
        return PriorityListDA.getPriority(getPriorityId()).getSeverity();
    }
    
    /**
     * @return the submitbyId
     */
    public int getSubmitById() {
        return submitById;
    }

    /**
     * @param submitbyId the submitbyId to set
     */
    public void setSubmitById(int submitbyId) {
        this.submitById = submitbyId;
    }

    /**
     * @return the submitbyName
     */
    public String getSubmitByName() {
        User us = UserListDA.getUser(getSubmitById());
        return (us.getFirstName() + " " + us.getLastName());
    }

    /**
     * @return the submitbyEmail
     */
    public String getSubmitByEmail() {
        User us = UserListDA.getUser(getSubmitById());
        return (us.getEmailAddress());
    }

    /**
     * @return the assigntoId
     */
    public int getAssignToId() {
        return assignToId;
    }

    /**
     * @param assigntoId the assigntoId to set
     */
    public void setAssignToId(int assigntoId) {
        this.assignToId = assigntoId;
    }

    /**
     * @return the assigntoName
     */
    public String getAssignToName() {
        User us = UserListDA.getUser(getAssignToId());
        return (us.getFirstName() + " " + us.getLastName());
    }

    /**
     * @return the assigntoEmail
     */
    public String getAssignToEmail() {
        User us = UserListDA.getUser(getSubmitById());
        return (us.getEmailAddress());
    }

    /**
     * @return the Status_id
     */
    public int getStatusId() {
        return statusId;
    }

    /**
     * @param status_id the Status_id to set
     */
    public void setStatusId(int status_id) {
        this.statusId = status_id;
    }

    /**
     * @return the Status
     */
    public String getStatus() {
     return StatusListDA.getStatus(getStatusId()).getStatus();
    }
    
    public String getCreatedDate() {
        return createdDate;
    }
}
